package com.example.idachuappone.index.entity;

import com.example.idachuappone.cook.entity.WorkDay;
import com.example.idachuappone.utils.ComUtil;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class HotService implements Serializable {
    private List<WorkDay> dates;
    private String description;
    private String from;
    private String head;
    private String id;
    private List<HotServiceItem> items;
    private String name;
    private String slogan;
    private String to;

    public void parseJson(JSONObject json) {
        if (json != null) {
            if (json.has("id")) {
                this.id = json.optString("id");
            }
            if (json.has("name")) {
                this.name = json.optString("name");
            }
            if (json.has("slogan")) {
                this.slogan = json.optString("slogan");
            }
            if (json.has("head")) {
                this.head = json.optString("head");
            }
            if (json.has("description")) {
                this.description = json.optString("description");
            }
            if (json.has("dates")) {
                if (json.optJSONObject("dates") != null) {
                    Iterator<String> iterator = json.optJSONObject("dates").keys();
                    this.dates = new ArrayList();
                    while (iterator.hasNext()) {
                        String key = (String) iterator.next();
                        try {
                            String ss = json.optJSONObject("dates").getString(key);
                            WorkDay workDay = new WorkDay(key);
                            workDay.parseJson(ss.substring(1, ss.length() - 1));
                            this.dates.add(workDay);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                    for (int x = 0; x < this.dates.size() - 1; x++) {
                        for (int y = 0; y < (this.dates.size() - x) - 1; y++) {
                            if (ComUtil.getDateLong1(((WorkDay) this.dates.get(y)).getDate()) > ComUtil.getDateLong1(((WorkDay) this.dates.get(y + 1)).getDate())) {
                                WorkDay item = (WorkDay) this.dates.get(y);
                                this.dates.set(y, (WorkDay) this.dates.get(y + 1));
                                this.dates.set(y + 1, item);
                            }
                        }
                    }
                }
            }
            if (json.has("items")) {
                List<HotServiceItem> list = new ArrayList();
                JSONArray jsonArray = json.optJSONArray("items");
                for (int i = 0; i < jsonArray.length(); i++) {
                    list.add(new HotServiceItem().parseJson(jsonArray.optJSONObject(i)));
                }
                this.items = list;
            }
            if (json.has("from")) {
                this.from = json.optString("from");
            }
            if (json.has("to")) {
                this.to = json.optString("to");
            }
        }
    }

    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSlogan() {
        return this.slogan;
    }

    public void setSlogan(String slogan) {
        this.slogan = slogan;
    }

    public String getHead() {
        return this.head;
    }

    public void setHead(String head) {
        this.head = head;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<WorkDay> getDates() {
        return this.dates;
    }

    public void setDates(List<WorkDay> dates) {
        this.dates = dates;
    }

    public List<HotServiceItem> getItems() {
        return this.items;
    }

    public void setItems(List<HotServiceItem> items) {
        this.items = items;
    }

    public String getFrom() {
        return this.from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getTo() {
        return this.to;
    }

    public void setTo(String to) {
        this.to = to;
    }
}
